package com.lkm.market2_0.m_imple.steelyardserver.server.cmd_handle;

import com.lkm.frame.P;
import com.lkm.javatool.NumberHelp;
import com.lkm.market2_0.ExpandConfig;
import com.lkm.market2_0.m.steelyarddata.SteelyardDataModule;
import com.lkm.market2_0.m.steelyardserver.SteelyardServerModule;
import com.lkm.market2_0.m_imple.steelyardserver.server.AbsReceiverDataHandle;
import com.lkm.market2_0.m_imple.steelyardserver.server.CMDEntity;
import com.lkm.market2_0.m_imple.steelyardserver.server.ICMDHandle;



@Deprecated 
public class CMDPrintADHandle implements ICMDHandle{

    SteelyardDataModule mSteelyardDataModule;
    SteelyardServerModule mSteelyardServerModule;

    public CMDPrintADHandle() {
        this.mSteelyardDataModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardDataModule.class);
        this.mSteelyardServerModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardServerModule.class);
    }

    
    public static int getAD(int num,byte [] data){
        if(data.length<30){
            return 0;
        }
        int offset = 2 + 4;
        return NumberHelp.bytesToIntDesc(new byte[]{data[14-offset], data[15-offset], data[16-offset], data[17-offset]});
    }
    
    public static int getZeroAD(int num,byte [] data){
        if(data.length<30){
            return 0;
        }
        int offset = 2 + 4;
        return NumberHelp.bytesToIntDesc(new byte[]{data[18-offset], data[19-offset], data[20-offset], data[21-offset]});
    }
    
    public static int getOffsetZeroAD(int num,byte [] data){
        if(data.length<30){
            return 0;
        }
        int offset = 2 + 4;
        return NumberHelp.bytesToIntDesc(new byte[]{data[22-offset], data[23-offset], data[24-offset], data[25-offset]});
    }
    
    public static int getKvalue(int num,byte [] data){
        if(data.length<30){
            return 0;
        }
        int offset = 2 + 4;
        return NumberHelp.bytesToIntDesc(new byte[]{data[26-offset], data[27-offset], data[28-offset], data[29-offset]});
    }
    @Override
    public AbsReceiverDataHandle handle(CMDEntity cmdEntity) {
        if(this.mSteelyardDataModule==null) {
            this.mSteelyardDataModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardDataModule.class);
        }
        if(this.mSteelyardServerModule==null) {
            this.mSteelyardServerModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardServerModule.class);
        }

        byte[] data= cmdEntity.getData();

        int ad = getAD(cmdEntity.getNum(),data);

//        if(P.isDebug()){
//            P.d("====称重AD"+ad);
//        }

        mSteelyardDataModule.AD(cmdEntity.getSteelyardMac(),ad,getZeroAD(cmdEntity.getNum(),data),getOffsetZeroAD(cmdEntity.getNum(),data),getKvalue(cmdEntity.getNum(),data));

        mSteelyardServerModule.tickOK_block(cmdEntity.getSteelyardMac());
        return null;
    }
}
